/***************************************************************************
 *   Copyright (C) 2009 by p1r0                                            *
 *   lucifers.preacher@gmail.com                                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

/**
* File Input/Output functions
*/

#include "fio.h"
#include "files.h"
#include "conf.h"

Handle<Value> ReadFileCallback(const Arguments& args)
{
    //This function gives direct access to the
    //system so if jail mode is on return inmediatly
    if(Conf::getInstance()->isJailed())
    {
        return v8::Undefined();
    }

    if (args.Length() < 1) return v8::Undefined();
    HandleScope scope;
    Handle<Value> arg = args[0];
    String::Utf8Value value(arg);
    char * contents;
    if(Files::load(*value, contents))
    {
        string cont = string(contents);
        delete[] contents;
        return String::New(cont.c_str());
    }


    return v8::Undefined();
}
